# This will re-generate the polyfill headers, if any file within libyul/backends/wasm/polyfill/ was modified.
set_directory_properties(PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/libyul/backends/wasm/polyfill/)

set(POLYFILLS Arithmetic Bitwise Comparison Conversion Interface Keccak Logical Memory)
set(GENERATED_POLYFILL_HEADERS)
foreach(polyfill IN LISTS POLYFILLS)
	set(POLYFILL_FILE ${CMAKE_SOURCE_DIR}/libyul/backends/wasm/polyfill/${polyfill}.yul)
	file(READ ${POLYFILL_FILE} EWASM_POLYFILL_CONTENT HEX)
	string(REGEX MATCHALL ".." EWASM_POLYFILL_CONTENT "${EWASM_POLYFILL_CONTENT}")
	string(REGEX REPLACE ";" ",\n\t0x" EWASM_POLYFILL_CONTENT "${EWASM_POLYFILL_CONTENT}")
	set(EWASM_POLYFILL_CONTENT "0x${EWASM_POLYFILL_CONTENT}")
	set(EWASM_POLYFILL_NAME ${polyfill})
	configure_file("${CMAKE_SOURCE_DIR}/cmake/templates/ewasm_polyfill.in" ${CMAKE_BINARY_DIR}/include/ewasmPolyfills/${polyfill}.h @ONLY)
	list(APPEND GENERATED_POLYFILL_HEADERS ${CMAKE_BINARY_DIR}/include/ewasmPolyfills/${polyfill}.h)
endforeach()

add_library(yul
	${GENERATED_POLYFILL_HEADERS}

	AsmAnalysis.cpp
	AsmAnalysis.h
	AsmAnalysisInfo.h
	AST.h
	ASTForward.h
	AsmJsonConverter.h
	AsmJsonConverter.cpp
	AsmJsonImporter.h
	AsmJsonImporter.cpp
	AsmParser.cpp
	AsmParser.h
	AsmPrinter.cpp
	AsmPrinter.h
	AssemblyStack.h
	AssemblyStack.cpp
	CompilabilityChecker.cpp
	CompilabilityChecker.h
	ControlFlowSideEffects.h
	ControlFlowSideEffectsCollector.cpp
	ControlFlowSideEffectsCollector.h
	Dialect.cpp
	Dialect.h
	Exceptions.h
	Object.cpp
	Object.h
	ObjectParser.cpp
	ObjectParser.h
	Scope.cpp
	Scope.h
	ScopeFiller.cpp
	ScopeFiller.h
	Utilities.cpp
	Utilities.h
	YulString.h
	backends/evm/AbstractAssembly.h
	backends/evm/AsmCodeGen.cpp
	backends/evm/AsmCodeGen.h
	backends/evm/ConstantOptimiser.cpp
	backends/evm/ConstantOptimiser.h
	backends/evm/ControlFlowGraph.h
	backends/evm/ControlFlowGraphBuilder.cpp
	backends/evm/ControlFlowGraphBuilder.h
	backends/evm/EthAssemblyAdapter.cpp
	backends/evm/EthAssemblyAdapter.h
	backends/evm/EVMCodeTransform.cpp
	backends/evm/EVMCodeTransform.h
	backends/evm/EVMDialect.cpp
	backends/evm/EVMDialect.h
	backends/evm/EVMObjectCompiler.cpp
	backends/evm/EVMObjectCompiler.h
	backends/evm/EVMMetrics.cpp
	backends/evm/EVMMetrics.h
	backends/evm/NoOutputAssembly.h
	backends/evm/NoOutputAssembly.cpp
	backends/evm/OptimizedEVMCodeTransform.cpp
	backends/evm/OptimizedEVMCodeTransform.h
	backends/evm/StackHelpers.h
	backends/evm/StackLayoutGenerator.cpp
	backends/evm/StackLayoutGenerator.h
	backends/evm/VariableReferenceCounter.h
	backends/evm/VariableReferenceCounter.cpp
	backends/wasm/EVMToEwasmTranslator.cpp
	backends/wasm/EVMToEwasmTranslator.h
	backends/wasm/BinaryTransform.cpp
	backends/wasm/BinaryTransform.h
	backends/wasm/TextTransform.cpp
	backends/wasm/TextTransform.h
	backends/wasm/WasmCodeTransform.cpp
	backends/wasm/WasmCodeTransform.h
	backends/wasm/WasmDialect.cpp
	backends/wasm/WasmDialect.h
	backends/wasm/WasmObjectCompiler.cpp
	backends/wasm/WasmObjectCompiler.h
	backends/wasm/WordSizeTransform.cpp
	backends/wasm/WordSizeTransform.h
	optimiser/ASTCopier.cpp
	optimiser/ASTCopier.h
	optimiser/ASTWalker.cpp
	optimiser/ASTWalker.h
	optimiser/BlockFlattener.cpp
	optimiser/BlockFlattener.h
	optimiser/BlockHasher.cpp
	optimiser/BlockHasher.h
	optimiser/CallGraphGenerator.cpp
	optimiser/CallGraphGenerator.h
	optimiser/CircularReferencesPruner.cpp
	optimiser/CircularReferencesPruner.h
	optimiser/CommonSubexpressionEliminator.cpp
	optimiser/CommonSubexpressionEliminator.h
	optimiser/ConditionalSimplifier.cpp
	optimiser/ConditionalSimplifier.h
	optimiser/ConditionalUnsimplifier.cpp
	optimiser/ConditionalUnsimplifier.h
	optimiser/ControlFlowSimplifier.cpp
	optimiser/ControlFlowSimplifier.h
	optimiser/DataFlowAnalyzer.cpp
	optimiser/DataFlowAnalyzer.h
	optimiser/DeadCodeEliminator.cpp
	optimiser/DeadCodeEliminator.h
	optimiser/Disambiguator.cpp
	optimiser/Disambiguator.h
	optimiser/EquivalentFunctionDetector.cpp
	optimiser/EquivalentFunctionDetector.h
	optimiser/EquivalentFunctionCombiner.cpp
	optimiser/EquivalentFunctionCombiner.h
	optimiser/ExpressionInliner.cpp
	optimiser/ExpressionInliner.h
	optimiser/ExpressionJoiner.cpp
	optimiser/ExpressionJoiner.h
	optimiser/ExpressionSimplifier.cpp
	optimiser/ExpressionSimplifier.h
	optimiser/ExpressionSplitter.cpp
	optimiser/ExpressionSplitter.h
	optimiser/ForLoopConditionIntoBody.cpp
	optimiser/ForLoopConditionIntoBody.h
	optimiser/ForLoopConditionOutOfBody.cpp
	optimiser/ForLoopConditionOutOfBody.h
	optimiser/ForLoopInitRewriter.cpp
	optimiser/ForLoopInitRewriter.h
	optimiser/FullInliner.cpp
	optimiser/FullInliner.h
	optimiser/FunctionCallFinder.cpp
	optimiser/FunctionCallFinder.h
	optimiser/FunctionDefinitionCollector.cpp
	optimiser/FunctionDefinitionCollector.h
	optimiser/FunctionGrouper.cpp
	optimiser/FunctionGrouper.h
	optimiser/FunctionHoister.cpp
	optimiser/FunctionHoister.h
	optimiser/FunctionSpecializer.cpp
	optimiser/FunctionSpecializer.h
	optimiser/InlinableExpressionFunctionFinder.cpp
	optimiser/InlinableExpressionFunctionFinder.h
	optimiser/KnowledgeBase.cpp
	optimiser/KnowledgeBase.h
	optimiser/LoadResolver.cpp
	optimiser/LoadResolver.h
	optimiser/LoopInvariantCodeMotion.cpp
	optimiser/LoopInvariantCodeMotion.h
	optimiser/MainFunction.cpp
	optimiser/MainFunction.h
	optimiser/Metrics.cpp
	optimiser/Metrics.h
	optimiser/NameCollector.cpp
	optimiser/NameCollector.h
	optimiser/NameDispenser.cpp
	optimiser/NameDispenser.h
	optimiser/NameDisplacer.cpp
	optimiser/NameDisplacer.h
	optimiser/NameSimplifier.cpp
	optimiser/NameSimplifier.h
	optimiser/OptimiserStep.h
	optimiser/OptimizerUtilities.cpp
	optimiser/OptimizerUtilities.h
	optimiser/ReasoningBasedSimplifier.cpp
	optimiser/ReasoningBasedSimplifier.h
	optimiser/RedundantAssignEliminator.cpp
	optimiser/RedundantAssignEliminator.h
	optimiser/RedundantStoreBase.cpp
	optimiser/RedundantStoreBase.h
	optimiser/Rematerialiser.cpp
	optimiser/Rematerialiser.h
	optimiser/SMTSolver.cpp
	optimiser/SMTSolver.h
	optimiser/SSAReverser.cpp
	optimiser/SSAReverser.h
	optimiser/SSATransform.cpp
	optimiser/SSATransform.h
	optimiser/SSAValueTracker.cpp
	optimiser/SSAValueTracker.h
	optimiser/Semantics.cpp
	optimiser/Semantics.h
	optimiser/SimplificationRules.cpp
	optimiser/SimplificationRules.h
	optimiser/StackCompressor.cpp
	optimiser/StackCompressor.h
	optimiser/StackLimitEvader.cpp
	optimiser/StackLimitEvader.h
	optimiser/StackToMemoryMover.cpp
	optimiser/StackToMemoryMover.h
	optimiser/StructuralSimplifier.cpp
	optimiser/StructuralSimplifier.h
	optimiser/Substitution.cpp
	optimiser/Substitution.h
	optimiser/Suite.cpp
	optimiser/Suite.h
	optimiser/SyntacticalEquality.cpp
	optimiser/SyntacticalEquality.h
	optimiser/TypeInfo.cpp
	optimiser/TypeInfo.h
	optimiser/UnusedFunctionParameterPruner.cpp
	optimiser/UnusedFunctionParameterPruner.h
	optimiser/UnusedFunctionsCommon.h
	optimiser/UnusedFunctionsCommon.cpp
	optimiser/UnusedPruner.cpp
	optimiser/UnusedPruner.h
	optimiser/VarDeclInitializer.cpp
	optimiser/VarDeclInitializer.h
	optimiser/VarNameCleaner.cpp
	optimiser/VarNameCleaner.h
)

target_link_libraries(yul PUBLIC evmasm solutil langutil smtutil fmt::fmt-header-only)
